package metronome;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Observable;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
 * The metronome.
 * @author Suwijak Suppapit 5510546204
 * @version 5/1/2013
 */
public class Metronome extends Observable{
	//beats per minute
	private double bpm;
	//time
	Date time;

	//state of application
	private MetronomeState state;
	//when playing
	public static MetronomeState playState;
	//when stop
	public static MetronomeState stopState;
	
	
	/**
	 * Initailize Metronome.
	 */
	public Metronome(){
		playState = new PlayState(this);
		stopState = new StopState(this);
		time = new Date();
		bpm = 60;
		
		state = stopState;
		
	}
	
	/**
	 * Beep the sounds depend on frequency.
	 * @throws LineUnavailableException
	 * @throws IOException
	 */
	public void beep() throws LineUnavailableException, IOException{

		state.beep();
	}
	
	
	/**
	 * Show time.
	 * @return time
	 */
	public Date getTime() {
		time.setTime(System.currentTimeMillis());
		return this.time;
	}
	/**
	 * Show up bpm.
	 * @return beats per min
	 */
	public double getBpm(){
		return this.bpm;
	}
	/**
	 * Set new frequency.
	 * @param bpm new frequency
	 */
	public void setBpm(double bpm){
		this.bpm = bpm;
		this.setChanged();
		this.notifyObservers(this);
	}
	/**
	 * Set states of metronome.
	 * @param state Metronome's states.
	 */
	public void setState(MetronomeState state){
		this.state = state;
	}
	/**
	 * Show state of metronome.
	 * @return state
	 */
	public MetronomeState getState(){
		return this.state;
	}
}
